﻿using ConsoleUtility.Command;
using System;

namespace ConsoleUtility.Tests.Demo
{
    [Command("demo", nameof(Demo.Greet))]
    public class Demo
    {
        [Option("smile", 's')]
        public bool ShowSmile { get; set; }

        [Option("name", 'n')]
        public string Name { get; set; }

        public Demo()
        {
            ShowSmile = false;
            Name = "world";
        }

        [Method("greet", 'G')]
        public void Greet()
        {
            var message = "Hello " + Name + "!";
            if (ShowSmile) { message += " : )"; }

            Console.WriteLine(message);
        }

        [Method("add", 'A')]
        public void Add(string a, string b)
        {
            double numA = 0;
            double numB = 0;

            if (!double.TryParse(a, out numA) || !double.TryParse(b, out numB))
            {
                Console.WriteLine("Parameters should be number.");
                return;
            }

            var message = string.Format("{0} + {1} = {2}", a, b, numA + numB);
            if (ShowSmile) { message += " : )"; }

            Console.WriteLine(message);
        }

        [Method("help", 'H')]
        public void Help()
        {
            string help = "\n" +
                "-G --greet                 Greet to world.\n" +
                "-A --add <num> <num>       Add two numbers.\n" +
                "-H --help                  Help.\n\n" +

                "-s --smile                 Show smile at the end.\n" +
                "-n --name <name>           Greet to you.\n";

            Console.WriteLine(help);
        }
    }
}
